function Iok = geneTrendFile(COut,filena)
% geneTrendFile - generates an Excel .xlsx file of GNSS station trends
%
%       Iok = geneTrendFile(COut,FILENA)
%
% Iok is true is the file generation with the trend cell variable COut
% and the output filename FILENA is successful, false elsewere.
% If FILENA is undefined or empty, the filename can be interactively 
% managed.

% G. Teza, 2021

if nargin < 2 || isempty(filena)
    [filename, pathname] = uiputfile( ...
        {'*.xlsx;*.xls', 'Excel Files (*.xlsx, *.xlsx)'}, ...
        'OUTPUT FILE');
    if isequal(filename,0) || isequal(pathname,0)
        disp('Invalid filename');
        Iok = false;
        return
    else
        filena = fullfile(pathname,filename);
    end
end

headCell = {'Station name','initial time','final time','Latitude (°)',...
    'Longitude (°)','Heigth (m)','E trend','N trend','V trend',...
    'E trend SD','N trend SD','V trend SD'};

CFin = [headCell; COut];

try
    xlswrite(filena,CFin);
    Iok = true;
catch 
    Iok = false;
end